#include "move.h"

Move::Move() {
	startType = "";
	endType = "";
	color = "";
	startCol = "";
	startRow = "";
	endCol = "";
	endRow = "";
	killType = "";
	kill = false;
	castle = false;
	enPassant = false;
}

std::string Move::stringifyType(ChessPiece * piece) {
	std::string answer = "";
	switch(piece->GetImage()) {
	case(B_PAWN):
	case(W_PAWN):
		answer += "pawn";
		break;
	case(B_ROOK):
	case(W_ROOK):
		answer += "rook";
		break;
	case(B_BISHOP):
	case(W_BISHOP):
		answer += "bishop";
		break;
	default:
                answer += moreTypeString(piece);
	}
	return answer;
}

std::string Move::moreTypeString(ChessPiece * p){
	std::string answer;
        switch(p->GetImage()){
	case(B_KING):
	case(W_KING):
		answer += "king";
		break;
	case(B_QUEEN):
	case(W_QUEEN):
		answer += "queen";
		break;
	case(B_KNIGHT):
	case(W_KNIGHT):
		answer += "knight";
		break;
	default:
	answer += "";
	}
	return answer;
}

std::string Move::stringifyColor(ChessPiece * p) {
	std::string ret;
	ret = (p->pColor == white) ? "white" : "black";
	return ret;
}

Move::Move(ChessPiece * start , ChessPiece * killPiece , int row , int col) {
	startType = stringifyType(start);
	startCol = MyFunctions::convertInt(start->col);
	startRow = MyFunctions::convertInt(start->row);
	color = stringifyColor(start);

	startColint = start->col;
	startRowint = start->row;

	endRowint = row;
	endColint = col;

	endType = stringifyType(start);
	endCol = MyFunctions::convertInt(col);
	endRow = MyFunctions::convertInt(row);
	kill = false;
	PawnPro = false;
	PassantRow = row;

	if(killPiece != NULL) {
		kill = true;
		killType = stringifyType(killPiece);
	}

}

void Move::didPromote(ChessPiece *p) {
	endType = stringifyType(p);
	PawnPro = true;

}

void Move::updateEnPassant() {
	if(color == "white") {
		endRow = MyFunctions::convertInt(PassantRow + 1);
		PassantRow = PassantRow + 1;
	} else {
		endRow = MyFunctions::convertInt(PassantRow - 1);
		PassantRow = PassantRow - 1;
	}
	kill = true;
	killType = "pawn";
}

void Move::updateCastle() {
	if(endColint == 2) {
		endCol = "3";
	}
	if(endColint == 6) {
		endCol = "5";
	}


	kill = true;
	killType = "rook";
	color = (color == "white") ? "black" : "white";
}

Move Move::operator =(Move &other) {
	startType = other.startType;
	endType = other.endType;
	color = other.color;
	startCol = other.startCol;
	startRow = other.startRow;
	endCol = other.endCol;
	endRow = other.endRow;
	killType = other.killType;
	kill = other.kill;
	castle = other.castle;
	enPassant = other.enPassant;

	PassantRow = other.PassantRow;
	startRowint = other.startRowint;
	endRowint = other.endRowint;
	startColint = other.startColint;
	endColint = other.endColint;
	PawnPro = other.PawnPro;
}
